<?php

namespace app\common\model;

use app\common\util\CommonUtil;
use think\facade\Cache;
use think\Model;

/**
 * 房屋配套信息
 */
class Infrastructure extends BaseModel
{

    // 表名,不含前缀
    protected $name = 'infrastructure';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;
    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;


    private function _decodeData($data)
    {
        if (!empty($data['icon'])) {
            $iconFile = (new Attachment())->findById($data['icon']);
            $data['iconFile'] = [
                'id' => $iconFile['id'],
                'url' => CommonUtil::formatHostUrl($iconFile['url'])
            ];
        }
        return $data;
    }

    public function selectById($id, $isAll)
    {
        $findData = $this->get($id);
        if (empty($findData)) return [];
        if ($isAll === false) return $findData;
        return $this->_decodeData($findData);
    }


}
